package com.ctshk.rpc.payment.strategy.impl;

import com.ctshk.rpc.payment.dto.UnionPayConfig;
import com.ctshk.rpc.payment.dto.req.unionpay.UnionPayTransReq;
import com.ctshk.rpc.payment.req.PayCommonReq;
import com.ctshk.rpc.payment.utils.PayUtil;
import com.ctshk.rpc.payment.utils.unionpay.UnionPayUtil;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.Map;

/**
 * @BelongsProject: ctshk-cloud
 * @BelongsPackage: com.ctshk.rpc.payment.strategy.impl
 * @Author: hef
 * @CreateTime: 2021-04-27 17:37
 * @Description: 描述
 */
@Component
public class UnionPayWapStrategy extends UnionPayStrategy {

    @Override
    public String pay(PayCommonReq req) {
        UnionPayConfig config = getConfig();
        Map<String, Object> data = new UnionPayTransReq(
                "08", config.getCallbackUrl(), config.getMerId(), String.valueOf(req.getOrderId()),
                LocalDateTime.now(), req.getTotalFee(), "156",config.getFrontUrl()
        ).toMap();
        Map<String, String> submitFromData = UnionPayUtil.signData(data);
        //待请求参数数组
        String toRet = PayUtil.joinParams(submitFromData);
        return toRet.substring(0, toRet.length() - 1);
    }
}
